package com.gpslw.security.config;

import com.gpslw.security.bean.UserInfo;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.GenericTypeResolver;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.core.GrantedAuthorityDefaults;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;

@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Bean(initMethod = "initMethod")
    UserInfo userInfo(){
        UserInfo userInfo = new UserInfo("yida","2019", AuthorityUtils.createAuthorityList("abc","root"));
        return userInfo;
    }

//    public void configure(WebSecurity web) throws Exception {
//    }
//
    protected void configure(HttpSecurity http) throws Exception {
//        http.authorizeRequests().antMatchers("/basic/**").permitAll().anyRequest().authenticated();
//        http.formLogin().and().httpBasic();
        http
                .csrf().disable()
                .exceptionHandling()
                .and()
                .authorizeRequests()
                .antMatchers("/**")
                .permitAll();
        http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
    }

}
